package com.xilihui.xlh.business.adapters;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.business.activitys.MergePaymentsActivity;
import com.xilihui.xlh.business.activitys.StartAppointmentActivity;
import com.xilihui.xlh.business.activitys.TakeGoodsActivity;
import com.xilihui.xlh.business.entities.DownloadMsg;
import com.xilihui.xlh.business.entities.HomeEntity;
import com.xilihui.xlh.business.requests.HomeRequest;
import com.xilihui.xlh.component.recyclerview.BaseAdapter;
import com.xilihui.xlh.component.recyclerview.BaseViewHolder;
import com.xilihui.xlh.core.http.DoTransform;
import com.xilihui.xlh.core.http.HttpSubscriber;

/**
 * Created by Administrator on 2018/5/31.
 */

public class AppointmentAdapter extends RecyclerView.Adapter<BaseViewHolder>{

    private static final int DOHINt = 1;
    private static final int DOTYPE = 2;
    private static final int HINT = 3;
    private static final int YYPE = 4;
    
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType){
            case DOHINt:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_apponitment_head
                ,parent,false);
                break;
            case DOTYPE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_appointment,
                        parent,false);
                break;
            case HINT:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_apponitment_head,
                        parent,false);
                break;
            case YYPE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_me_appointment,
                        parent,false);
                break;
        }
        return new BaseViewHolder(view);
    }
    
    
    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        switch (getItemViewType(position)){
            case DOHINt:
                holder.setVisibility(R.id.rl_fukuang,View.GONE);
                TextView textView1 = (TextView)holder.getView(R.id.tv_hint);
                textView1.setText("正在进行的预约");
                break;
            case DOTYPE:
                
                holder.setOnClickListener(R.id.tv_take, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        view.getContext().startActivity(new Intent(view.getContext(),TakeGoodsActivity.class));
                    }
                });
                
                break;
            case HINT:
                final TextView textView = (TextView)holder.getView(R.id.tv_hint);
                textView.setBackgroundColor(textView.getContext().getResources().getColor(R.color.bg_383b3c));
                textView.setText("我的预约");
                textView.setTextColor(textView.getContext().getResources().getColor(android.R.color.white));
                
                holder.setOnClickListener(R.id.tv_hebinfukuang, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        textView.getContext().startActivity(new Intent(textView.getContext(),
                                MergePaymentsActivity.class));
                    }
                });
                
                break;
            case YYPE:
                
                holder.setOnClickListener(R.id.tv_take, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(view.getContext(),TakeGoodsActivity.class);
                        view.getContext().startActivity(new Intent(view.getContext(),
                                TakeGoodsActivity.class));
                    }
                });
                
                holder.setOnClickListener(R.id.tv_startAppointment, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        view.getContext().startActivity(new Intent(view.getContext(),
                                StartAppointmentActivity.class));
                    }
                });
                         
                break;
        }
    }

    @Override
    public int getItemCount() {
        return 8;
    }

    @Override
    public int getItemViewType(int position) {
        if(position==0){
            return 1;
        }else if(position<=2){
            return 2;
        }else if(position==3){
            return 3;
        }else{
            return 4;
        }
    }
    
    
}
